package com.spring.sunflower.dialog;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.lxj.xpopup.core.CenterPopupView;
import com.spring.sunflower.R;
import com.spring.sunflower.constant.Constant;

/**
 * Created by Kevin on 2021/9/1<br/>
 * <p>
 * Describe:<br/>
 */
public class TaskFinishDialog extends CenterPopupView implements View.OnClickListener {

    private final String gender;
    private Context context;

    public TaskFinishDialog(@NonNull Context context) {
        super(context);
        gender = SPUtils.getInstance().getString(Constant.KEY_GENDER, "1");
        this.context = context;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_task_finish;
    }

    private TextView tvAward;
    private TextView tvDone, tvMoreAward;
    private ImageView ivMoney;

    @Override
    protected void onCreate() {
        super.onCreate();
        tvAward = findViewById(R.id.tvAward);
        tvDone = findViewById(R.id.tvDone);
        tvMoreAward = findViewById(R.id.tvMoreAward);
        ivMoney = findViewById(R.id.ivMoney);
        if ("1".equals(gender)) {
            Glide.with(context)
                    .load(R.drawable.ic_money)
                    .into(ivMoney);
        } else {
            Glide.with(context)
                    .load(R.drawable.ic_income_diamond)
                    .into(ivMoney);
        }
        tvDone.setOnClickListener(this);
        tvMoreAward.setOnClickListener(this);
        if (listener != null) {
            listener.onCrateView();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvDone:
                dismiss();
                break;
            case R.id.tvMoreAward:
                if (listener != null) {
                    listener.onMoreClick();
                }
                dismiss();
                break;
        }
    }

    public void showAward(String str) {
        tvAward.setText(str);
    }

    private OnTaskFinishListener listener;

    public void setOnTaskFinishListener(OnTaskFinishListener l) {
        listener = l;
    }

    public interface OnTaskFinishListener {
        void onCrateView();

        void onMoreClick();
    }
}
